from django.contrib.syndication.feeds import Feed
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed

import app_settings
from models import Entry

class FeedLatestEntriesRss(Feed):
    feed_type = Rss201rev2Feed
    _title = "%s's latest messages"
    link = app_settings.MICROBLOG_URL_BASE
    _description = 'Latest message received by %s'

    def __init__(self, user, slug, request):
        self.user = user
        super(FeedLatestEntriesRss, self).__init__(slug, request)

    def title(self):
        return self._title % self.user.username

    def description(self):
        return self._description % self.user.username

    def items(self):
        return self.user.received_entries.all()[:app_settings.MICROBLOG_FEEDS_MAX_ITEMS]

class FeedLatestEntriesAtom(FeedLatestEntriesRss):
    feed_type = Atom1Feed
    subtitle = FeedLatestEntriesRss.description

